package com.test.java;

import java.util.Scanner;

/**
 * 正整数A的“DA（为1位整数）部分”定义为由A中所有DA组成的新整数PA。例如：给定A = 3862767，DA = 6，则A的“6部分”PA是66，因为A中有2个6。
 * 现给定A、DA、B、DB，请编写程序计算PA + PB。
 * =============================================================
 * Version          Author          Date            Description
 * 1.0              白建         2017/12/18             创建
 * =============================================================
 */
public class Java_7
{

    private static String A, DA, B, DB;

    public static void main(String[] args)
    {

        init();
        process();
    }

    private static void init()
    {

        Scanner scanner = new Scanner(System.in);
        String temp = scanner.nextLine();
        String[] strings = temp.split(" ");
        A = strings[0];
        DA = strings[1];
        B = strings[2];
        DB = strings[3];
    }

    private static void process()
    {

        byte countA = 0, countB = 0;
        double sum = 0.0;
        for (int i = 0; i < A.length(); i++)
        {
            if (A.charAt(i) == DA.charAt(0))
            {
                countA++;
            }
        }
        for (int i = 0; i < B.length(); i++)
        {
            if (B.charAt(i) == DB.charAt(0))
            {
                countB++;
            }
        }
        for (int i = 0; i < countA; countA--)
        {
            sum += Integer.parseInt(DA) * Math.pow(10, countA - 1);
        }
        for (int i = 0; i < countB; countB--)
        {
            sum += Integer.parseInt(DB) * Math.pow(10, countB - 1);
        }

        System.out.println(((int) sum));
    }
}
